﻿using Coldairarrow.Business;
using Coldairarrow.Entity;
using Coldairarrow.IBusiness;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers
{
    [Route("/Comment/[controller]/[action]")]
    public class Invoice_InfoController : BaseApiController
    {
        #region DI

        public Invoice_InfoController(IInvoice_InfoBusiness invoice_InfoBus, IOperator @operator)
        {
            _invoice_InfoBus = invoice_InfoBus;
            _operator = @operator;
        }
        readonly IOperator _operator;
        private IInvoice_InfoBusiness _invoice_InfoBus { get; }

        #endregion DI

        #region 获取

        [HttpPost]
        public async Task<PageResult<Invoice_Info>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _invoice_InfoBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 个人中心——获取我的发票列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Invoice_Info>> GetsMyInvoce()
        {
            return await _invoice_InfoBus.GetMyInvoce();
        }

        [HttpPost]
        public async Task<Invoice_Info> GetTheData(IdInputDTO input)
        {
            return await _invoice_InfoBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 发票指定查询历史
        /// </summary>
        /// <param name="Phone"></param>
        /// <returns></returns>
        [HttpPost]
        public List<Invoice_Info> GetInvoice(string Phone)
        {
            return _invoice_InfoBus.GetInvoice(Phone);
        }
        #endregion 获取

        #region 提交

        /// <summary>
        /// 添加发票
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Invoice_Info> SaveTwoData(Invoice_Info data)
        {
            InitEntity(data);
            data.Deleted = true;
            data.CreatorId = _operator.UserId;
            return await _invoice_InfoBus.AddDataTwoAsync(data);
        }

        [HttpPost]
        public async Task SaveData(Invoice_Info data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                data.Deleted = true;
                data.CreatorId = _operator.UserId;

                await _invoice_InfoBus.AddDataAsync(data);
            }
            else
            {
                await _invoice_InfoBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _invoice_InfoBus.DeleteDataAsync(ids);
        }

        #endregion 提交
    }
}